<template>
	<view class="f-danmu-box">
		<scroll-view scroll-y="true" scroll-with-animation class="pl-3 scroll-view" :scroll-into-view="scrollInToView">
			<view v-for="(item,index) in list" :key="index" :id="'danmu'+item.id"
				class="rounded flex justify-start align-start p-2 mb-2 danmu-item">
				<text class="font text-danger">{{item.name}}：</text>
				<text class="font text-white">{{item.content}}</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scrollInToView: "",
				list: []
			}
		},
		mounted() {

		},
		methods: {
			send(data) {
				this.list.push(data)
				// 置于底部
				this.toBottom()
			},
			toBottom() {
				// 这里有问题，如果没有倒计时的话，不会滚到最底部
				setTimeout(() => {
					let len = this.list.length
					if (len > 0 && this.list[len - 1]) {
						this.scrollInToView = 'danmu' + this.list[len - 1].id
					}
				}, 200)
			}
		}
	}
</script>

<style>
	.f-danmu-box {
		position: fixed;
		left: 0;
		bottom: 120rpx;
		right: 0;
	}

	.scroll-view {
		width: 520rpx;
		height: 300rpx;
	}

	.danmu-item {
		background-color: rgba(255, 255, 255, 0.125);
	}
</style>
